using System;
using System.IO;

namespace Caramel.IO
{
	public static class FileInfoExtensions
	{
		public static IFileInfo CopyTo(this IFileInfo fileInfo, string destFileName)
		{
			return
				fileInfo.
					CopyTo(
						destFileName,
						false
					);
		}

		public static Stream Open(this IFileInfo fileInfo, FileMode mode)
		{
			return
				fileInfo.
					Open(
						mode,
						(mode == FileMode.Append) ? FileAccess.Write : FileAccess.ReadWrite
					);
		}

		public static Stream Open(this IFileInfo fileInfo, FileMode mode, FileAccess access)
		{
			return
				fileInfo.
					Open(
						mode,
						access,
						FileShare.None
					);
		}

		public static IFileInfo Replace(this IFileInfo fileInfo, string destinationFileName, string destinationBackupFileName)
		{
			return 
				fileInfo.
					Replace(
						destinationFileName, 
						destinationBackupFileName,
						false
					);
		}
	}
}
